const app = getApp();
Page({
    data: {
        BoxData: '',
        currx:0,
        netErr: 0,
    },
    onLoad(options) {
        this.replaceAjax();
    },
    /*分店列表*/
    replaceAjax() {
        app.request.request({
            link: '/api/supplier/merchant_list',
            methodtype: 'POST',
            ting: {
                brand_id: app.globalData.brand.brand_id
            },
            succ: (res) => {
                console.log(res)
                let Boxs = res.data.data, BoxMeta = res.data.message, currx = 0;
                if (res.data.status == 200) {
                    Boxs.merchant_list.forEach((i, x) => {
                        i.logo = app.request.picAdd + i.logo;
                        console.log(app.globalData.my.merchant_id)
                        if (i.merchant_id == app.globalData.my.merchant_id){
                            currx=x
                        }
                    });
                    this.setData({
                        BoxData: Boxs.merchant_list,
                        currx: currx,
                    })
                } else {
                    app.util.showModal(false, '提示', BoxMeta, () => wx.navigateBack({ delta: 1 }))
                }
            },
            fail: (err) => {
                this.setData({
                    netErr: 1,
                })
            }
        })
    },
    /*选择更新分店*/
    Toupdate(e){
        app.request.must.merchant_id = this.data.BoxData[e.currentTarget.dataset.inx].merchant_id;
        app.globalData.my = app.Transfer({ name: 'fyzs_info', info: this.data.BoxData[e.currentTarget.dataset.inx] });
        this.setData({
            currx:e.currentTarget.dataset.inx
        })
    },
    /*网络报错*/
    ErrorF5() {
        this.replaceAjax();
        this.setData({
            netErr: 0,
        })
    },
    
})